package com.itheima.reggie.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R doOtherException(SQLIntegrityConstraintViolationException sqlex){
        sqlex.printStackTrace();
        String message = sqlex.getMessage();
        String[] split = message.split(" ");
        return R.error(split[2]+"已存在");
    }

    /**
     * 异常处理方法
     * @return
     */
    @ExceptionHandler(CustomException.class)
    public R<String> exceptionHandler(CustomException ex){
        return R.error(ex.getMessage());
    }



}
